package service

import (
	"account/dao"
	"account/dto"
	"account/models"
)

// 定义AccountService结构体，返回AccountDao
type AccountService struct {
	accountDao *dao.AccountDao
}

// 定义实例化AccountService的方法
func NewAccountService(accountDao *dao.AccountDao) *AccountService {
	return &AccountService{accountDao: accountDao}
}

// 定义添加账单记录的方法
func (as *AccountService) AddAccount(account *models.Account) error {
	return as.accountDao.AddAccount(account)
}

// 定义根据日期查看支出的方法
func (as *AccountService) GetOutCome(date string) (float64, error) {
	return as.accountDao.GetOutCome(date)
}

// 定义根据日期查看收入的方法
func (as *AccountService) GetInCome(date string) (float64, error) {
	return as.accountDao.GetInCome(date)
}

// GetAccountsWithPagination 获取分页账户数据
// func (as *AccountService) PaginateAccountsWithCondition(page int, startDate, endDate, category string) (*dto.PaginateResult, error) {

// 	accounts, total, err := as.accountDao.PaginateAccountsWithCondition(page, startDate, endDate, category)
// 	if err != nil {
// 		return nil, err
// 	}

// 	return &dto.PaginateResult{
// 		Total: total,
// 		Page:  page,
// 		Data:  accounts,
// 	}, nil
// }

// 分页查询所有记录
// func (as *AccountService) GetAllAccountWithLimit(page int) (*dto.PaginateResult, error) {
// 	accounts, total, err := as.accountDao.GetAllAccountWithLimit(page)
// 	if err != nil {
// 		return nil, err
// 	}

// 	return &dto.PaginateResult{
// 		Total: total,
// 		Page:  page,
// 		Data:  accounts,
// 	}, nil
// }

// 终极分页查询
func (as *AccountService) GetAccounts(page int, startDate, endDate, category string) (*dto.PaginateResult, error) {
    accounts, total, err := as.accountDao.GetAccounts(page , startDate, endDate, category )
	if err != nil {
		return nil, err
	}

	return &dto.PaginateResult{
		Total: total,
		Page:  page,
		Data:  accounts,
	}, nil
}
 